/*
 *******************************************************************************
 * All rights Reserved, Copyright (C) www.gm-sz.com 2013
 * FileName: login.js
 * Modify record:
 * NO. |     Date       |    Version      |    Name         |      Content
 * 1   | 2013年11月7日         |      1.0        | GMSZ)LuHaosheng | original version
 *******************************************************************************
 */

var login = login || {};

/**
 * Description: 初始化
 */

login.loadLogin = function(type) {
	if(type==0){
		document.getElementById('userName').focus();
		
		var oldValue = null;
		$('input').unbind('keydown keyup').keydown(function(event) {
			var me = $(this);
			if (event.which == 13) {
				oldValue = me.val();
			}
		}).keyup(function(event) {
			var me = $(this);
			if (event.which == 13 && me.val() == oldValue) {
				login.dologin(type);
			}
		});
	}else{
		login.dologin(type);
	}
};
/**
 * Description: 登录
 */
login.dologin = function(type) {
	var url = commonutil.actionPath + '/login';
	var password = $('#password').val();
	var pass = CryptoJS.SHA1(password).toString();
	commonutil.doAjax(url, {'username': $('#userName').val(), 'password': pass,'type':type}, function(data) {
		if (data.resultValue == true) {
			window.location.href = commonutil.path + data.message;
		} else {
			$('#errorMsg').text('');
			$('#errorMsg').text(data.message);
			$('#errorRow').show();
		}
	}, 'json');
};

login.index = function(type) {
	window.location.href =commonutil.path;
};

login.loadLogin(0);